package com.bytz.modules.common.exception;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @program: cms-backend
 * @description:
 * @author: KyleWang
 * @create: 2023-11-24 13:46
 **/

public class BaseBizException extends RuntimeException {


    private int code;

    public BaseBizException(int code) {
        this.code = code;
    }

    public BaseBizException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BaseBizException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public BaseBizException(int code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    @Override
    public String toString() {
        String clazzName = getClass().getName();
        String message = getLocalizedMessage();
        return (StringUtils.isNotBlank(message)) ? (clazzName + ": " + message) : (clazzName + ": " + code + "。");
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }
}